using System.Web.Security;
using eManager.Domain;
using WebMatrix.WebData;

namespace eManager.web.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<eManager.web.Infrastructure.DepartementDb>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(eManager.web.Infrastructure.DepartementDb context)
        {
          context.Departements.AddOrUpdate(d=>d.Name,
            new Departement{Name = "enginnering"},
            new Departement(){Name = "Sales"},
            new Departement(){Name = "Shipping"},
            new Departement(){Name = "Humain Ressources"}
            );

          WebSecurity.InitializeDatabaseConnection(
              "DefaultConnection",
              "UserProfile",
              "UserId",
              "UserName", autoCreateTables: true);

            if (!Roles.RoleExists("Admin"))
            {
                Roles.CreateRole("Admin");
            }

            if (!WebSecurity.UserExists("helmi"))
                WebSecurity.CreateUserAndAccount(
                    "helmi",
                    "password");

            if (!Roles.GetRolesForUser("helmi").Contains("Admin"))
                Roles.AddUsersToRoles(new[] { "helmi" }, new[] { "Admin" });
        }
    }
}
